local MenuOpen = false
local MatchStarted = false
local MatchData = {}
local QueuedPlayers = 0
local MatchPlayers = 0


net.Receive("ShowMatchMakingMenu", function()
	if(!MenuOpen)then
		ShowMatchMakingWindow()
	end
end)

net.Receive("SendMatchData", function()
	MatchData = net.ReadTable()
	if(MenuOpen)then
		UpdateMatchData()
	end
end)

net.Receive("SendAllSpells", function() 
	AllSpells = net.ReadTable()
end)

function ShowMatchMakingWindow()
	timer.Create("RetrieveMatchData", 2, 0, function()
		net.Start("RetrieveMatchData")
		print("a")
		net.SendToServer()
	end)

	surface.PlaySound("devin/blackbetty/menu/spellbook_open.wav")
	MenuOpen = true
	mmMenu = vgui.Create("DFrame")
		mmMenu:SetTitle( "Match Status" )
		mmMenu:SetSize( 500, 800 )
		mmMenu:SetDeleteOnClose(true)
		mmMenu:ShowCloseButton(true)
		mmMenu:Center()
		mmMenu:SetMouseInputEnabled(true)
		mmMenu:MakePopup()
		mmMenu.Close = function() 
		MenuOpen = false 
		surface.PlaySound("devin/blackbetty/menu/spellbook_close.wav") 
		mmMenu:Remove()
		timer.Destroy("RetrieveMatchData")
		end
		
	BookPages = vgui.Create( "DPropertySheet", mmMenu )
		BookPages:SetPos( 5, 30 )
		BookPages:SetSize( 490, 765-35 )
		BookPages:SetFadeTime(0)
		
	local MatchText1 = vgui.Create( "DLabel",  mmMenu )
		MatchText1:SetFont("HUDText_Vendor")
		MatchText1:SetText( "Match Status:" )
		MatchText1:SetPos(120, 45)
		MatchText1:SizeToContents()
		MatchText1:SetTextColor( Color(255, 255, 255, 235) )
		
	local MatchTextPanel1 = vgui.Create("DPanel", BookPages)
		MatchTextPanel1:SetPos( 0,  0)
		MatchTextPanel1:SetSize( 490, 60 )
		MatchTextPanel1:SetBackgroundColor(Color(0, 0, 0, 140))
		
	UpdateMatchData()
end

function UpdateMatchData()
	
	if(MatchText2 != nil)then
		MatchText2:Remove()
	end
	if(MatchStarted)then
		MatchText2 = vgui.Create( "DLabel",  mmMenu )
			MatchText2:SetFont("HUDText_Vendor")
			MatchText2:SetText( "In Progress" )
			MatchText2:SetPos(220, 45)
			MatchText2:SizeToContents()
			MatchText2:SetTextColor( Color(255, 255, 25, 235) )
	else
		MatchText2 = vgui.Create( "DLabel",  mmMenu )
			MatchText2:SetFont("HUDText_Vendor")
			MatchText2:SetText( "Not Started" )
			MatchText2:SetPos(268, 45)
			MatchText2:SizeToContents()
			MatchText2:SetTextColor( Color(25, 255, 25, 235) )
	end
	if(MatchTextPanel2 != nil)then
		MatchTextPanel2:Remove()
	end
	
	local MatchTextPanel2 = vgui.Create("DPanel", BookPages)
		MatchTextPanel2:SetPos( 0,  70)
		MatchTextPanel2:SetSize( 490, 60 )
		MatchTextPanel2:SetBackgroundColor(Color(0, 0, 0, 140))
	
end